package top.juntower.utils;

import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

/**
 * 网络请求库
 */
public class OkHttpUtil {
    public static String getToken="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx5688ab219c701677&secret=c5b04b8ecd15f612e7338f352a44d257";
    public static String checkContent="https://api.weixin.qq.com/wxa/msg_sec_check?access_token=";
    private String data = null;
    Request request = null;

    public String okHttp(String url, RequestBody body) {
        OkHttpClient client = new OkHttpClient();
        try {
            if (body != null) {
                //post方法
                request = new Request.Builder()
                        .url(url)
                        .post(body)
                        .build();
                Call call = client.newCall(request);
                data = call.execute().body().string();
            } else {
                //get方法
                request = new Request.Builder()
                        .url(url)
                        .get()
                        .build();
                Call call = client.newCall(request);
                data = call.execute().body().string();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return data;
    }


}
